package com.myprinciple.singleton.type8;

/**
 * @author zhupanlin
 * @version 1.0
 * @description: TODO
 * @date 2024/4/10 18:44
 */
public class SingletonTest08 {

    public static void main(String[] args) {
        Singleton instance = Singleton.INSTANCE;
        Singleton instance1 = Singleton.INSTANCE;
        // true 表示两个对象为同一个引用 
        System.out.println(instance1 == instance);
        System.out.println("instance.hashCode() = " + instance.hashCode());
        System.out.println("instance1.hashCode() = " + instance1.hashCode());
        
        instance.sayOK();
    }
    
}

// 使用枚举，可以实现单例，推荐
enum Singleton {
    INSTANCE; // 属性
    public void sayOK(){
        System.out.println("ok~~");
    }
}
